package GUI;

import Model.Gates.Gate;
import Model.Inputs.Button;
import Model.Inputs.Input;
import Model.Main.Wire;
import java.awt.Dimension;
import java.awt.Point;
import java.util.ArrayList;
import javax.imageio.ImageIO;
import javax.swing.JOptionPane;

/**
 *
 * @author bg
 */
public class ButtonView extends AbstractElementView {

    Button button;

    public ButtonView(Button button, Point position) {
        
        outputs = new ArrayList<Point>();
        try {
            img = ImageIO.read(getClass().getResource("Images/button.png"));
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Nincsen " + this.getClass().getName() + " kép!");
        }
        state = false;
        this.button = button;
        this.position = position;
        this.preferredImageSize = new Dimension(30, 64);

        for (int i = Math.round(64 / (button.getMaxOutput() + 1)); i < 60; i += Math.round(64 / (button.getMaxOutput() + 1))) {
            outputs.add(new Point(position.x + 30, position.y + i));
        }
    }

    @Override
    void click() {
        try {
            if (state == false) {
                img = ImageIO.read(getClass().getResource("Images/button1.png"));
                state = true;
                button.setState(true);
            } else {
                img = ImageIO.read(getClass().getResource("Images/button.png"));
                state = false;
                button.setState(false);
            }

        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Nincsen " + this.getClass().getName() + " kép!!!");
        }
    }

    @Override
    void setOutputWireModel(Wire w, int inputNumber) {

        button.setOutputWire(w);
    }

    @Override
    Gate getGate() {
        return null;
    }

    Input getInput() {
        return button;
    }
}
